<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>ZDH 数据基础信息</title>
    <meta name="keywords" content="ZDH 数据基础信息">
    <meta name="description" content="ZDH 数据基础信息">

    <link rel="shortcut icon" href="img/favicon.ico">

    <link href="css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="css/font-awesome.css?v=4.4.0" rel="stylesheet">
    <link href="css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="css/animate.css" rel="stylesheet">
    <link href="css/style.css?v=4.1.0" rel="stylesheet">
    <link href="css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
    <!--    <link rel="stylesheet" type="text/css" href="css/plugins/webuploader/webuploader.css">
        <link rel="stylesheet" type="text/css" href="css/demo/webuploader-demo.css">-->

</head>

<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">

    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>数据信息</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="buttons.html#">
                            <i class="fa fa-eye"></i>
                        </a>
                        <ul class="dropdown-menu dropdown-user">
                            <li><a href="javascript:void(0);" onclick="getResourceDesc()">功能说明</a>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="ibox-content">

                    <div class="row">
                        <div class="col-sm-12">
                            <div class="tabs-container">
                                <ul class="nav nav-tabs">
                                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">基本信息</a>
                                    </li>
                                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="true">字段信息</a>
                                    </li>
                                    <li class=""><a data-toggle="tab" href="#tab-3" aria-expanded="true">分区信息</a>
                                    </li>
                                    <li class=""><a data-toggle="tab" href="#tab-4" aria-expanded="true">样本数据</a>
                                    </li>
                                    <li class=""><a data-toggle="tab" href="#tab-5" aria-expanded="true">已申请组</a>
                                    </li>
                                </ul>
                                <div class="tab-content">
                                    <div id="tab-1" class="tab-pane active">
                                        <div class="panel-body">
                                            <form id="etl_task_add_form" name="etl_task_add_form" method="post" class="form-horizontal"
                                                  action="">

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">数据说明</label>
                                                    <div class="col-sm-10">
                                                        <input id="issue_context" name="issue_context" type="text" readonly
                                                               placeholder="数据说明" class="form-control" aria-required="true"> </span>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">创建时间</label>
                                                    <div class="col-sm-10">
                                                        <input id="create_time" name="create_time" type="text" readonly
                                                               placeholder="创建时间" class="form-control" aria-required="true"> </span>
                                                    </div>
                                                </div>

                                                <div class="hr-line-dashed"></div>
                                                <!-- 输入数据源开始-->
<!--                                                <div class="form-group">-->
<!--                                                    <label class="col-sm-2 control-label">选择数据源</label>-->
<!--                                                    <div class="col-sm-10">-->
<!--                                                        <select id="data_sources_choose_input" name="data_sources_choose_input"-->
<!--                                                                data-placeholder="选择数据源..."-->
<!--                                                                class="chosen-select form-control m-b" tabindex="2">-->
<!--                                                            <option value="" mytype="">选择数据源...</option>-->
<!--                                                        </select>-->
<!--                                                    </div>-->
<!--                                                </div>-->

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">数据源类型</label>
                                                    <div class="col-sm-10">
                                                        <input id="data_source_type_input" name="data_source_type_input" type="text" readonly
                                                               placeholder="数据源类型" class="form-control" aria-required="true"> </span>
                                                    </div>
                                                </div>


                                                <div class="hr-line-dashed"></div>

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">表名/文件名</label>
<!--                                                    <div class="col-sm-10" id="div_data_sources_table_name_input">-->
<!--                                                        <select id="data_sources_table_name_input" name="data_sources_table_name_input"-->
<!--                                                                data-placeholder="选择数据表..."-->
<!--                                                                class="chosen-select form-control m-b" tabindex="2">-->
<!--                                                            <option value="">选择数据表...</option>-->
<!--                                                        </select>-->
<!--                                                    </div>-->

                                                    <div class="col-sm-10" id="div_data_sources_file_name_input">
                                                        <input id="data_sources_file_name_input" name="data_sources_file_name_input" type="text" readonly
                                                               placeholder="表名/文件名" class="form-control" aria-required="true"> </span>
                                                    </div>
                                                </div>

                                                <!-- 元信息 业务相关-->

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">发布人</label>
                                                    <div class="col-sm-10">
                                                        <input id="user_name" name="user_name"
                                                               type="text" readonly
                                                               placeholder="发布人" class="form-control" aria-required="true"> </span>
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">所属公司</label>
                                                    <div class="col-sm-10">
                                                        <input id="company" name="company"
                                                               type="text" readonly
                                                               placeholder="填写公司" class="form-control" aria-required="true"> </span>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">所属部门</label>
                                                    <div class="col-sm-10">
                                                        <input id="section" name="section"
                                                               type="text" readonly
                                                               placeholder="填写部门" class="form-control" aria-required="true"> </span>
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">所属业务</label>
                                                    <div class="col-sm-10">
                                                        <input id="service" name="service"
                                                               type="text" readonly
                                                               placeholder="填写业务" class="form-control" aria-required="true"> </span>
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="col-sm-2 control-label">更新说明</label>
                                                    <div class="col-sm-10">
                                                            <textarea id="update_context" name="update_context" class="form-control" rows="2" readonly
                                          placeholder="更新说明"></textarea>
                                                    </div>
                                                </div>

                                                <div class="hr-line-dashed"></div>
                                                <!-- 输出数据源结束-->

                                            </form>
                                        </div>
                                    </div>
                                    <div id="tab-2" class="tab-pane">
                                        <div class="panel-body">
                                            <form id="etl_task_add_form2" name="etl_task_add_form2" method="post" class="form-horizontal"
                                                  action="">



                                                <div class="form-group">

                                                    <label class="col-sm-2 control-label">配置字段映射</label>
                                                    <div class="col-sm-10">

                                                        <table id="exampleTableEvents" name="exampleTableEvents" data-height="100%"
                                                               data-mobile-responsive="false">

                                                        </table>
                                                        <!-- End Example Events -->

                                                    </div>
                                                </div>

                                            </form>
                                        </div>
                                    </div>
                                    <div id="tab-3" class="tab-pane">
                                        <div class="panel-body">

                                        </div>
                                    </div>
                                    <div id="tab-4" class="tab-pane">
                                        <div class="panel-body">
                                            <form id="etl_task_add_form4" name="etl_task_add_form4" method="post" class="form-inline"
                                                  action="">
                                                <div class="form-group">
                                                    <div class="input-group" >
                                                        <input id="context" name="context" class="form-control" type="text" value="" placeholder="关键词">
                                                        <span class="add-on"><i class="icon-remove"></i></span>
                                                        <span class="add-on"><i class="icon-calendar"></i></span>
                                                    </div>
                                                </div>
                                                <div class="form-group">
                                                    <input id="search" οnsubmit='return false' type="button" class="btn btn-primary form-control" style="margin-bottom:0px" value="查询"/>
                                                </div>
                                                <div class="form-group">
                                                    <input id="export" οnsubmit='return false' type="button" class="btn btn-primary form-control" style="margin-bottom:0px" value="导出"/>
                                                </div>
                                                <br/>
                                                <br/>
                                            </form>
                                            <div class="row">
                                                <div class="col-sm-12">

                                                    <table id="exampleTableEvents2" name="exampleTableEvents2" data-height="100%"
                                                           data-mobile-responsive="false">

                                                    </table>
                                                    <!-- End Example Events -->

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div id="tab-5" class="tab-pane">
                                        <div class="panel-body">
                                            <div class="row">
                                                <div class="col-sm-12">
                                                    <div class="btn-group" id="exampleTableEventsToolbar" role="group">
                                                        <button id="notice_downstream" type="button" class="btn btn-outline btn-default">
                                                            通知下游
<!--                                                            <i class="glyphicon glyphicon-plus" aria-hidden="true"></i>-->
                                                        </button>
                                                    </div>
                                                    <table id="exampleTableEvents3" name="exampleTableEvents3" data-height="100%"
                                                           data-mobile-responsive="false">

                                                    </table>
                                                    <!-- End Example Events -->

                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>


                            </div>
                        </div>
                    </div>

                </div>
            </div>


        </div>
    </div>
</div>

<script src="js/zdh_common.js"></script>
<!-- 全局js -->
<script src="js/jquery.min.js?v=2.1.4"></script>
<script src="js/bootstrap.min.js?v=3.3.6"></script>

<!-- Bootstrap table -->
<script src="js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
<script src="js/plugins/bootstrap-table/bootstrap-table-mobile.min.js"></script>
<script src="js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
<!-- 自定义js -->
<script src="js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="js/plugins/slimscroll/jquery.slimscroll.min.js"></script>
<script src="js/hplus.js"></script>
<script src="js/content.js"></script>

<!-- Chosen -->
<script src="js/plugins/chosen/chosen.jquery.js"></script>

<!-- layer javascript -->
<script src="js/plugins/layer/layer.min.js"></script>

<!-- iCheck -->
<script src="js/plugins/iCheck/icheck.min.js"></script>
<script>
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
    });


    (function (document, window, $) {


        (function () {

            var url = location.search; //这一条语句获取了包括问号开始到参数的最后，不包括前面的路径
            var params = url.substr(1);//去掉问号
            var pa = params.split("&");
            var s = new Object();//定义一个全局变量-存储任务ID
            for (var i = 0; i < pa.length; i++) {
                s[pa[i].split("=")[0]] = unescape(pa[i].split("=")[1]);
            }

            $('#file_type_input').chosen();
            $('#encoding_input').chosen();
            $('#header_input').chosen();
            $('#file_type_output').chosen();
            $('#encoding_output').chosen();
            $('#header_output').chosen();

            //定义特定数据源展示的div
            function fileShow() {
                console.info("fileShow");
                $('#div_data_sources_file_name_input')[0].style.display = 'block';
            }


            window.operateEvents = {
                'click #del': function (e, value, row, index) {
                    $('#exampleTableEvents').bootstrapTable('remove', {field: 'column_md5', values: [row.column_md5]});
                }
            };

            function operateFormatter(value, row, index) {
                return [
                    ' <button id="del" name="del" type="button" class="btn btn-outline btn-sm">\n' +
                    '                                        <i class="glyphicon glyphicon-trash" aria-hidden="true"></i>\n' +
                    '                                    </button>'
                ].join('');
            }

            //初始化 bootstrap table
            $('#exampleTableEvents').bootstrapTable({
                url: "",
                search: false,
                clickEdit: true,
                pagination: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                useRowAttrFunc: true,
                iconSize: 'outline',
                //toolbar: '#exampleTableEventsToolbar',
                icons: {
                    refresh: 'glyphicon-repeat',
                    toggle: 'glyphicon-list-alt',
                    columns: 'glyphicon-list'
                },
                columns: [
                    {
                        field: 'nu',
                        title: '序号',
                        formatter: function (value, row, index) {
                            return index + 1;
                        }
                    }, {
                        field: 'column_name',
                        title: '原始字段',
                        sortable: false
                    },{
                        field: 'column_type',
                        title: '数据类型',
                        sortable: false
                    }, {
                        field: 'column_is_null',
                        title: '是否可空',
                        sortable: false
                    }, {
                        field: 'column_desc',
                        title: '数据说明',
                        sortable: false
                    }]
            });

            function saveData(index, field, value) {
                $('#exampleTableEvents').bootstrapTable('updateCell', {
                    index: index,       //行索引
                    field: field,       //列名
                    value: value        //cell值
                })
            }

            fileShow();
            //启动数据源select 初始化函数
            //init_data_sources();
            //s.id=-1 表示新增,否则表示更新
            if (s.id == -1) {
                console.info("新增按钮触发");
                $('#save_etl_task').show()

            } else {
                build_param(s.id)
            }

            function build_param(id){
                   // 数据渲染
                    $.ajax({
                        type: 'POST',
                        url: server_context+"/data_ware_house_list",
                        dataType: 'json',
                        data: "id="+id,
                        //成功返回
                        success: function (data) {
                            if(data.code != "200"){
                                layer.msg(data.msg);
                                return ;
                            }
                            // 基础信息加载
                            $('#issue_context').val(data.result.issue_context);
                            $('#create_time').val(getMyDate(data.result.create_time));
                            $('#data_source_type_input').val(data.result.data_source_type_input);
                            $('#data_sources_file_name_input').val(data.result.data_sources_table_name_input);
                            $('#user_name').val(data.result.user_name);
                            $('#company').val(data.result.company);
                            $('#section').val(data.result.section);
                            $('#service').val(data.result.service);
                            // 字段信息加载
                            var column_datas = data.result.column_datas;
                            var cd = JSON.parse(column_datas);
                            var columnsArray=new Array();
                            columnsArray.push({field: "state", checkbox: true});
                            for (var i = 0; i < cd.length; i++) {
                                var index = $('#exampleTableEvents').bootstrapTable('getData').length;
                                $('#exampleTableEvents').bootstrapTable('insertRow', {
                                    index: index,
                                    row: {
                                        // column_md5: cd[i].column_md5,
                                        column_name: cd[i].column_name,
                                        //column_expr: cd[i].column_expr,
                                        column_type: cd[i].column_type,
                                        column_length: cd[i].column_length,
                                        column_is_null: cd[i].column_is_null,
                                        //column_regex: cd[i].column_regex,
                                        column_desc: cd[i].column_desc,
                                        //column_alias: cd[i].column_alias
                                    }
                                });

                                columnsArray.push({
                                    "title": cd[i].column_name,
                                    "field": cd[i].column_name,
                                    switchable: true,
                                    sortable: true});
                            }


                            //生成表格
                            $('#exampleTableEvents2').bootstrapTable({
                                url: "",
                                search: true,
                                clickEdit: false,
                                pagination: false,
                                showRefresh: false,
                                showToggle: false,
                                showColumns: true,
                                useRowAttrFunc: true,
                                iconSize: 'outline',
                                //toolbar: '#exampleTableEventsToolbar',
                                icons: {
                                    refresh: 'glyphicon-repeat',
                                    toggle: 'glyphicon-list-alt',
                                    columns: 'glyphicon-list'
                                },
                                columns: columnsArray,
                                // 请求完成回调 可处理请求到的数据
                                responseHandler: res => {
                                    // 关闭加载层
                                    return res.result;
                                },
                                onLoadSuccess: function (ee)
                                {
                                    //查询数据成功
                                    if(ee.code == "201"){
                                        layer.msg(ee.result);
                                    }
                                }
                            });
                        },
                        //处理完成
                        complete: function () {
                            console.info("complete")
                        },
                        //报错
                        error: function (data) {
                            console.info("error: " + data.responseText);
                        }
                    });

                // 字段信息加载
                var columnsArray=new Array();
                columnsArray.push({
                    "title": "用户名",
                    "field": "user_name",
                    switchable: true,
                    sortable: true});

                //生成表格
                $('#exampleTableEvents3').bootstrapTable({
                    method: "POST",
                    url: server_context+"/data_ware_house_apply?issue_id="+id,
                    search: true,
                    clickEdit: false,
                    pagination: false,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: true,
                    useRowAttrFunc: true,
                    iconSize: 'outline',
                    responseHandler:function (res) {
                        if(res.code == "201"){
                            layer.msg(res.msg);
                        }
                        return res.result;
                    },
                    //toolbar: '#exampleTableEventsToolbar',
                    icons: {
                        refresh: 'glyphicon-repeat',
                        toggle: 'glyphicon-list-alt',
                        columns: 'glyphicon-list'
                    },
                    columns: columnsArray
                });
            }

            function getMyDate(str) {
                var oDate = new Date(str),
                    oYear = oDate.getFullYear(),
                    oMonth = oDate.getMonth() + 1,
                    oDay = oDate.getDate(),
                    oHour = oDate.getHours(),
                    oMin = oDate.getMinutes(),
                    oSen = oDate.getSeconds(),
                    oTime = oYear + '-' + getzf(oMonth) + '-' + getzf(oDay) + " " + getzf(oHour) + ":" + getzf(oMin) + ":" + getzf(oSen);//最后拼接时间
                return oTime;
            };

            //补0操作
            function getzf(num) {
                if (parseInt(num) < 10) {
                    num = '0' + num;
                }
                return num;
            }

            function openTabPage(url, title) {
                var wpd = $(window.parent.document);
                var mainContent = wpd.find('.J_mainContent');
                var thisIframe = mainContent.find("iframe[data-id='" + url + "']");
                var pageTabs = wpd.find('.J_menuTabs .page-tabs-content ');
                pageTabs.find(".J_menuTab.active").removeClass("active");
                mainContent.find("iframe").css("display", "none");
                if (thisIframe.length > 0) {	// 选项卡已打开
                    thisIframe.css("display", "inline");
                    pageTabs.find(".J_menuTab[data-id='" + url + "']").addClass("active");
                } else {
                    var menuItem = wpd.find("a.J_menuItem[href='" + url + "']");
                    var dataIndex = title == undefined ? menuItem.attr("data-index") : '9999';
                    var _title = title == undefined ? menuItem.find('.nav-label').text() : title;
                    var iframe = '<iframe class="J_iframe" name="iframe' + dataIndex + '" width="100%" height="100%" src="' + url + '" frameborder="0" data-id="' + url
                        + '" seamless="" style="display: inline;"></iframe>';
                    pageTabs.append(
                        ' <a href="javascript:;" class="J_menuTab active" data-id="' + url + '">' + _title + ' <i class="fa fa-times-circle"></i></a>');
                    mainContent.append(iframe);
                    //显示loading提示
                    var loading = top.layer.load();
                    mainContent.find('iframe:visible').load(function () {
                        //iframe加载完成后隐藏loading提示
                        top.layer.close(loading);
                    });
                }

            }

            function closeTab() {
               // var currentWidth = $(this).parents('.J_menuTab').width();
                var wpd = $(window.parent.document);
                var mainContent = wpd.find('.J_mainContent');
                var pageTabs = wpd.find('.J_menuTabs .page-tabs-content ');
                var currentTab=pageTabs.find(".J_menuTab.active");
                var closeTabId = currentTab.data('id');
                mainContent.find('.J_iframe');

                // 当前元素处于活动状态
                if (currentTab.hasClass('active')) {

                    // 当前元素后面有同辈元素，使后面的一个元素处于活动状态
                    if (pageTabs.next('.J_menuTab').size()) {

                        var activeId = currentTab.next('.J_menuTab:eq(0)').data('id');
                        currentTab.next('.J_menuTab:eq(0)').addClass('active');

                        mainContent.find('.J_iframe').each(function (index,e) {
                            if ($(e).data('id') == activeId) {
                                $(e).show().siblings('.J_iframe').hide();
                                return false;
                            }
                        });

                        var marginLeftVal = parseInt($('.page-tabs-content').css('margin-left'));
                        if (marginLeftVal < 0) {
                            pageTabs.animate({
                                marginLeft: (marginLeftVal + currentTab.width()) + 'px'
                            }, "fast");
                        }

                        //  移除当前选项卡
                        currentTab.remove();

                        // 移除tab对应的内容区
                        mainContent.find('.J_iframe').each(function (index,e) {
                            alert($(e).data('id'));
                            if ($(e).data('id') == closeTabId) {
                                $(e).remove();
                                return false;
                            }
                        });
                    }

                    // 当前元素后面没有同辈元素，使当前元素的上一个元素处于活动状态
                    if (currentTab.prev('.J_menuTab').size()) {
                        var activeId = currentTab.prev('.J_menuTab:last').data('id');
                        currentTab.prev('.J_menuTab:last').addClass('active');
                        mainContent.find('.J_iframe').each(function (index,e) {
                            if ($(e).data('id') == activeId) {
                                $(e).show().siblings('.J_iframe').hide();
                                return false;
                            }
                        });

                        //  移除当前选项卡
                        currentTab.remove();

                        // 移除tab对应的内容区
                        mainContent.find('.J_iframe').each(function (index,e) {
                            if ($(e).data('id') == closeTabId) {
                                $(e).remove();
                                return false;
                            }
                        });

                    }
                }
                // 当前元素不处于活动状态
                else {

                    //  移除当前选项卡
                    currentTab.remove();

                    // 移除相应tab对应的内容区
                    mainContent.find('.J_iframe').each(function (index,e) {
                        if ($(e).data('id') == closeTabId) {
                            $(e).remove();
                            return false;
                        }
                    });
                   // scrollToTab($('.J_menuTab.active'));
                }
                return false;
            }

        })();

    })(document, window, jQuery);

    $(document).ready(function () {
        var url = location.search; //这一条语句获取了包括问号开始到参数的最后，不包括前面的路径
        var params = url.substr(1);//去掉问号
        var pa = params.split("&");
        var s = new Object();//定义一个全局变量-存储任务ID
        for (var i = 0; i < pa.length; i++) {
            s[pa[i].split("=")[0]] = unescape(pa[i].split("=")[1]);
        }
        $('#search').click(function () {
            $('#exampleTableEvents2').bootstrapTable('refresh', {
                url: server_context+"/data_ware_house_sample?"+$("#etl_task_add_form4").serialize()+"&id="+s.id,
                contentType: "application/json;charset=utf-8",
                dataType: "json"
            });
        });
        $('#export').click(function () {
            window.open(server_context+"/data_ware_house_export?id="+s.id,);
        });

        $('#notice_downstream').click(function () {
            parent.layer.open({
                type: 2,
                title: '通知下游',
                shadeClose: false,
                resize: true,
                fixed: false,
                maxmin: true,
                shade: 0.1,
                area : ['45%', '60%'],
                //area: ['450px', '500px'],
                content: server_context+"/notice_downstream_email_index?id="+s.id, //iframe的url
                end : function () {
                    console.info("弹框结束");
                }
            });
        })

    })
</script>

</body>

</html>
